// 正则表达式初步验证登录时输入的信息是否正确

function check() {
    let tip = document.getElementsByName("tips");
    let reg_text = /^[a-zA-Z0-9]{6,15}$/;

    let x = document.getElementById("username").value;
    if (x == "") {
        tip[0].innerHTML = "请填写你的用户名!";
        return false;
    } else if (!reg_text.test(x)) {
        tip[0].innerHTML = "用户名格式不对，用户名应该是6~15个字符!";
        return false;
    } else tip[0].innerHTML = "&ensp;";

    let y = document.getElementById("password").value;
    if (y == "") {
        tip[1].innerHTML = "请填写你的密码!";
        return false;
    } else if (!reg_text.test(y))
        tip[1].innerHTML = "密码格式不对，密码应该是6~15个字符!";
    else tip[1].innerHTML = "&ensp;";
}


$(function () {
    $("#customerBtn").click(function () {
        $.post("../customerVerification",
            {"username": $("#username").val(), "password": $("#password").val()},
            function (json, status) {
                if (status == "success") {
                    if (json.success) {
                        document.location.href = "../customerMenu";
                    } else {
                        $("#tipMsg").empty();
                        $("#tipMsg").append("用户名不存在或者密码错误，请重新登录");
                    }
                } else alert(status);
            },
            "JSON"
        );
    });

    $("#adminBtn").click(function () {
        $.post("../adminVerification",
            {"username": $("#username").val(), "password": $("#password").val()},
            function (json, status) {
                if (status == "success") {
                    if (json.success) {
                        document.location.href = "../adminMenu";
                    } else {
                        $("#tipMsg").empty();
                        $("#tipMsg").append("用户名不存在或者密码错误，请重新登录");
                    }
                } else alert(status);
            },
            "JSON"
        );
    });
});
